package ysq.xyg.recovery.controller;

import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.recovery.model.po.RecoveryComplain;
import ysq.xyg.recovery.model.vo.RecoveryComplainVo;
import ysq.xyg.recovery.service.RecoveryComplainService;
import ysq.xyg.web.model.po.WebMember;
import ysq.xyg.web.service.WebMemberService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-投诉表controller层
 *
 * @author congcong tao
 * @date 2019-7-30 20:19:27
 */
@RestController
public class RecoveryComplainController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(RecoveryComplainController.class);
    @Resource
    private RecoveryComplainService recoveryComplainService;
    @Resource
    private WebMemberService webMemberService;
    private RecoveryComplain recoveryComplain;

    /**
     * 分页查询
     *
     * @param recoveryComplainVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-7-30 20:19:27
     */
    @BaseLog(module = "回收金模块",className = "投诉表",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryComplain/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoveryComplainVo recoveryComplainVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoveryComplainService.pageLeft(recoveryComplainVo,pageSize,pageNum);
        return returnEntity;
    }
    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-30 20:19:27
     */
    @RequestMapping(value = "/recoveryComplain/getPrinter",method = RequestMethod.GET)
    public ModelAndView getPrinter(String id){
        ModelAndView view = new ModelAndView("/recovery/recoveryComplainprinter");
        recoveryComplain = recoveryComplainService.selectByPrimaryKey(id);
        String image = recoveryComplain.getImage();
        if (StringUtils.isNotEmpty(image)) {
            view.addObject("imageArr", image.split(","));
        }
        view.addObject("recoveryComplain", recoveryComplain);
        view.addObject("webMember", webMemberService.selectByPrimaryKey(recoveryComplain.getMemberId()));
        return view;
    }
    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-30 20:19:27
     */
    @RequestMapping(value = "/recoveryComplain/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoveryComplainUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            recoveryComplain = recoveryComplainService.selectByPrimaryKey(id);
            String image = recoveryComplain.getImage();
            if (StringUtils.isNotEmpty(image)) {
                view.addObject("imageArr", image.split(","));
            }
            view.addObject("recoveryComplain", recoveryComplain);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-30 20:19:27
     */
    @BaseLog(module = "回收金模块",className = "投诉表",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryComplain/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoveryComplainService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param recoveryComplainVo Vo对象
     * @author congcong tao
     * @date 2019-7-30 20:19:27
     */
    @BaseLog(module = "回收金模块",className = "投诉表",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryComplain/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity addOrUpdate(HttpServletRequest request,RecoveryComplainVo recoveryComplainVo){
        return recoveryComplainService.addOrUpdate(recoveryComplainVo,acceptCurrentUser(request));
    }

    @RequestMapping(value = "/recoveryComplain/updateStatus",method = RequestMethod.POST)
    public ReturnEntity updateStatus(HttpServletRequest request, RecoveryComplainVo recoveryComplainVo){
        RecoveryComplain recoveryComplain = recoveryComplainService.selectByPrimaryKey(recoveryComplainVo.getId());
        recoveryComplain.setStatus(recoveryComplainVo.getStatus());
        recoveryComplainService.updateByPrimaryKey(recoveryComplain);
        return new ReturnEntity();
    }
}